<template>
  <el-table
    :data="tableData"
    :header-cell-style="{ textAlign: 'center' }"
    :cell-style="{ textAlign: 'center', padding: '7px' }"
    :row-class-name="tableRowClassName"
  >
    <el-table-column label="通道" prop="tunnelNum"></el-table-column>
    <el-table-column label="监测类型" prop="dataType"></el-table-column>
    <el-table-column label="测值（mm）" prop="realData"></el-table-column>
    <el-table-column label="采集时间" prop="creatTime"></el-table-column>
  </el-table>
</template>

<script>
import Axios from "axios";
import moment from "moment";
import * as serviceApi from "../../../../common/service.config";
Axios.defaults.withcredentials = true;

export default {
  name: "DeepAndCrack",
  props: {
    node: Object,
  },
  data() {
    return {
      tableData: null,
    };
  },
  methods: {
    tableRowClassName({ rowIndex }) {
      if (rowIndex % 2 === 1) {
        return "row01";
      } else {
        return "row02";
      }
    },
  },
  created() {
    Axios({
      url: serviceApi.KB_API,
      method: "post",
      data: `appMsg={"parameter":"{\\"sensorNumber\\":\\"${this.node.sensorNumber}\\",\\"dataType\\":\\"01\\",\\"sensorName\\":\\"${this.node.sensorName}\\"}","serviceCode":"queryRealDataBySensorNo","timestamp":"","uuid":""}`,
    }).then((res) => {
      let list = res.data.parameter;
      for (let i = 0; i < list.length; i++) {
        list[i].tunnelNum = `通道${list[i].tunnelNum}`;
        list[i].creatTime = moment(Number(list[i].creatTime)).format(
          "YYYY-MM-DD HH:mm:ss"
        );
        switch (list[i].dataType) {
          case "01":
            list[i].dataType = "测斜";
            list[i].realData = Number(list[i].realData).toFixed(3);
            break;
          case "02":
            list[i].dataType = "裂缝";
            list[i].realData = Number(list[i].realData).toFixed(1);
        }
      }
      this.tableData = list;
    });
  },
};
</script>

<style lang="less" scoped>
.el-table {
  /deep/ .row01 {
    background: #ffbab7;
  }
  /deep/ .row02 {
    background: #c7efcf;
  }
}
</style>